use gio::prelude::*;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow, Button};
pub fn main() {
    let application = Application::builder()
        .application_id("com.example.FirstGtkApp")
        .build();
    application.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_title(Some("HelloRust"));
        window.set_default_size(350, 70);

        let outer_box = gtk::Box::new(gtk::Orientation::Vertical, 0);
        let inner_box = gtk::Box::new(gtk::Orientation::Horizontal, 0);
        let entry: gtk::Entry = gtk::Entry::new();
        entry.set_size_request(500, 15);
        entry.set_margin_start(10);
        entry.set_margin_end(10);
        entry.set_margin_top(10);
        entry.set_max_width_chars(20);
        let brief = gtk::TextView::new();
        brief.set_halign(gtk::Align::Start); // 10 pixel right margin
        brief.set_editable(false);
        brief.set_size_request(500, 30);
        // brief.get_buffer().unwrap().set_text("收款方（Bob）地址：XXX.XXX.XXX.XXX");
        brief.set_margin_start(10);
        brief.set_margin_end(10);
        brief.set_margin_top(20);
        // brief.override_background_color(
        //     gtk::StateFlags::from_bits(gtk::StateFlags::NORMAL.bits()).unwrap(),
        //     Some(&RGBA {
        //         red: 0.965,
        //         green: 0.96,
        //         blue: 0.957,
        //         alpha: 1f64,
        //     }),
        // );
        let details = gtk::TextView::new();
        details.set_halign(gtk::Align::Start); // 10 pixel right margin
        details.set_editable(false);
        details.set_size_request(50, 30);
        // details.get_buffer().unwrap().set_text("金额：");
        details.set_margin_start(10);
        details.set_margin_end(10);
        details.set_margin_top(20);
        // details.override_background_color(
        //     gtk::StateFlags::from_bits(gtk::StateFlags::NORMAL.bits()).unwrap(),
        //     Some(&RGBA {
        //         red: 0.965,
        //         green: 0.96,
        //         blue: 0.957,
        //         alpha: 1f64,
        //     }),
        // );
        let button = Button::with_label("Alice发起转账");
        button.set_size_request(300, 20);
        button.set_margin_start(30);
        button.set_margin_end(30);
        button.set_margin_top(30);
        let confirm_button = Button::with_label("Bob确认交易并签名");
        confirm_button.set_size_request(300, 20);
        confirm_button.set_margin_start(30);
        confirm_button.set_margin_end(30);
        confirm_button.set_margin_top(30);
        let verify_button = Button::with_label("Alice校验交易合法性");
        verify_button.set_size_request(100, 20);
        verify_button.set_margin_start(30);
        verify_button.set_margin_end(30);
        verify_button.set_margin_top(30);
        let logtext = gtk::TextView::new();
        logtext.set_halign(gtk::Align::Start); // 10 pixel right margin
        logtext.set_editable(false);
        logtext.set_size_request(950, 300);
        // logtext.get_buffer();//().unwrap().set_text("");
        logtext.set_margin_start(10);
        logtext.set_margin_end(10);
        logtext.set_margin_top(20);
        inner_box.append(&details);
        inner_box.append(&entry);
        outer_box.append(&brief);
        outer_box.append(&inner_box);
        outer_box.append(&button);
        outer_box.append(&confirm_button);
        outer_box.append(&verify_button);
        outer_box.append(&logtext);
        window.set_child(Some(&outer_box));

        // let amount_buffer = entry.get_buffer();
        button.connect_clicked(move |_| {
            // let re = Regex::new(r"^[0-9]*[1-9][0-9]*$").unwrap();
            // let amount = amount_buffer.get_text();
            // if re.is_match(&amount) {
            //     //输入金额合法
            // } else {
            //     //请输入正确的金额，需是正整数
            // }
        });
        window.present();
    });
    application.run();
}
